package com.hjm.project.record.purchaserRecord.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.record.purchaserRecord.domain.PurchaserUpdateRecord;
import com.hjm.project.record.purchaserRecord.service.IPurchaserUpdateRecordService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 终端购买人变更记录Controller
 * 
 * @author maker-platform
 * @date 2022-10-31
 */
@Controller
@RequestMapping("/record/purchaserRecord")
public class PurchaserUpdateRecordController extends BaseController {
    private String prefix = "record/purchaserRecord";

    @Resource
    private IPurchaserUpdateRecordService purchaserUpdateRecordService;

    @RequiresPermissions("record:purchaserRecord:view")
    @GetMapping()
    public String purchaserRecord() {
        return prefix + "/purchaserRecord";
    }

    /**
     * 查询终端购买人变更记录列表
     */
        @RequiresPermissions("record:purchaserRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PurchaserUpdateRecord purchaserUpdateRecord) {
        startPage();
        List<PurchaserUpdateRecord> list = purchaserUpdateRecordService.selectPurchaserUpdateRecordList(purchaserUpdateRecord);
        return getDataTable(list);
    }

    /**
     * 导出终端购买人变更记录列表
     */
    @RequiresPermissions("record:purchaserRecord:export")
    @Log(title = "终端购买人变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PurchaserUpdateRecord purchaserUpdateRecord) {
        List<PurchaserUpdateRecord> list = purchaserUpdateRecordService.selectPurchaserUpdateRecordList(purchaserUpdateRecord);
        ExcelUtil<PurchaserUpdateRecord> util = new ExcelUtil<PurchaserUpdateRecord>(PurchaserUpdateRecord.class);
        return util.exportExcel(list, "purchaserRecord");
    }

    /**
     * 新增终端购买人变更记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存终端购买人变更记录
     */
    @RequiresPermissions("record:purchaserRecord:add")
    @Log(title = "终端购买人变更记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PurchaserUpdateRecord purchaserUpdateRecord) {
        return toAjax(purchaserUpdateRecordService.insertPurchaserUpdateRecord(purchaserUpdateRecord));
    }

    /**
     * 修改终端购买人变更记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        PurchaserUpdateRecord purchaserUpdateRecord = purchaserUpdateRecordService.selectPurchaserUpdateRecordById(id);
        mmap.put("purchaserUpdateRecord", purchaserUpdateRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存终端购买人变更记录
     */
    @RequiresPermissions("record:purchaserRecord:edit")
    @Log(title = "终端购买人变更记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PurchaserUpdateRecord purchaserUpdateRecord) {
        return toAjax(purchaserUpdateRecordService.updatePurchaserUpdateRecord(purchaserUpdateRecord));
    }

    /**
     * 删除终端购买人变更记录
     */
    @RequiresPermissions("record:purchaserRecord:remove")
    @Log(title = "终端购买人变更记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(purchaserUpdateRecordService.deletePurchaserUpdateRecordByIds(ids));
    }

    @GetMapping("/purchaserRecordDetails")
    public String purchaserRecordDetails(@RequestParam String batch, ModelMap mmp){
        mmp.addAttribute("batch",batch);
        return prefix + "/purchaserRecordDetails";
    }

    /**
     * 查询终端购买人变更记录详情
     */
    @PostMapping("/detail")
    @ResponseBody
    public TableDataInfo detail(PurchaserUpdateRecord purchaserUpdateRecord) {
        startPage();
        List<PurchaserUpdateRecord> list = purchaserUpdateRecordService.selectPurchaserUpdateRecordDetail(purchaserUpdateRecord);
        return getDataTable(list);
    }

    /**
     * 导出终端购买人变更记录列表
     */
    @Log(title = "终端购买人变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDetail")
    @ResponseBody
    public AjaxResult exportDetail(PurchaserUpdateRecord purchaserUpdateRecord) {
        List<PurchaserUpdateRecord> list = purchaserUpdateRecordService.selectPurchaserUpdateRecordDetail(purchaserUpdateRecord);
        ExcelUtil<PurchaserUpdateRecord> util = new ExcelUtil<PurchaserUpdateRecord>(PurchaserUpdateRecord.class);
        return util.exportExcel(list, "purchaserRecord");
    }

}
